﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fotobanka
{
    public partial class SpravaUzivatelu : System.Web.UI.Page
    {
        GroupManager gm;
        protected void Page_Load(object sender, EventArgs e)
        {
            gm = new GroupManager();
        }

        protected void addButton_Click(object sender, EventArgs e)
        {
            if (gm.UserExistInGroup(Convert.ToInt32(Request.QueryString["id"]), Convert.ToInt32(lide.SelectedItem.Value.ToString())))
            {
                errors.Text = "Tento uživatel již existuje v teto skupině";
            } else {
                errors.Text = "";
                gm.InsertUserToGroup(Convert.ToInt32(Request.QueryString["id"]), Convert.ToInt32(lide.SelectedItem.Value.ToString()));
                GridView1.DataBind();
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                foreach (DataControlField dcf in ((GridView)sender).Columns)
                {
                    if (dcf.ToString() == "CommandField")
                    {
                        if (((CommandField)dcf).ShowDeleteButton == true)
                        {
                            e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Attributes
                            .Add("onclick", "return confirm(\"Opravdu chcete smazat?\")");
                        }
                    }
                }
            }
        }
    }
}
